import { Component, OnInit, ViewChild, AfterContentInit, Input, ChangeDetectorRef } from '@angular/core';
import { SchoolService } from 'src/app/benshuo/services/school.service';
import { MessagesService } from 'src/app/benshuo/services/messages.service';
import { G2BarData, G2BarComponent } from '@delon/chart';

@Component({
  selector: 'app-school-show-count',
  templateUrl: './school-show-count.component.html',
  styleUrls: [],
})
export class SchoolShowCountComponent implements OnInit {
  /**
   * 调用api 标志
   */
  loading = false;

  @ViewChild('tu', null)
  tu: G2BarComponent;

  salesData: any[] = [];

  constructor(private messages: MessagesService, private cdr: ChangeDetectorRef) {
    this.load();
  }

  ngOnInit(): void {}

  load() {
    this.loading = true;
    this.messages.findSchoolUserCount().subscribe(
      data => {
        this.loading = true;
        data.forEach(it => {
          this.salesData.push({ x: it.key, y: it.value });
        });
        setTimeout(() => {
          this.loading = false;
          this.salesData = [...this.salesData];
          this.cdr.markForCheck();
        }, 1000);
      },
      () => {},
      () => {},
    );
  }
}
